package com.mxx.common.netty.http;

import java.io.Serializable;

/**
 * @Auther: Mr. Zeng
 * @Date: 2020/6/29 11:23
 * @Description: 暂无描述
 */
public final class NettyResponse<T> implements Serializable {
    private int code;
    private String msg;
    private T data;

    public NettyResponse() {
    }

    public NettyResponse(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    @Override
    public String toString() {
        return "Response{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }


    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }

    public static <T> NettyResponse<T> ok(T data) {
        return new NettyResponse<>(200, "ok", data);
    }

    public static NettyResponse<Void> ok() {
        return new NettyResponse(200, "ok", null);
    }

    public static <T> NettyResponse<T> ok(String msg, T data) {
        return new NettyResponse<>(200, msg, data);
    }

    public static NettyResponse fail(String msg) {
        return new NettyResponse<String>(500, msg, null);
    }
}